package ink.ykb.demo.permission.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ink.ykb.demo.config.CodeConstant;
import ink.ykb.demo.config.MessageUtil;
import ink.ykb.demo.config.ResponseMsg;
import ink.ykb.demo.permission.annotation.Function;
import ink.ykb.demo.permission.entity.UserDealerDepartment;
import ink.ykb.demo.permission.service.UserDealerDepartmentService;

/**
 * 用户经销商层级相关服务
 * 
 * @author mading
 *
 */
@RestController
@RequestMapping("/dealerDepartment/user")
public class UserDealerDepartmentController {

  @Autowired
  private UserDealerDepartmentService userDealerDepartmentService;
  @Autowired
  private MessageUtil messageUtil;

  
  /**
   * 添加用户经销商层级
   * @param userDealerDepartment 参数：userId,dealerDepartmentId
   * @return
   */
  @Function("admin.dealerDepartment.user.add")
  @PostMapping(value = "/add")
  public ResponseMsg<String> add(UserDealerDepartment userDealerDepartment) {
    userDealerDepartmentService.add(userDealerDepartment);
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS));
  }
  
  /**
   * 修改用户经销商层级
   * @param userId
   * @param dealerDepartmentId
   * @param scope
   * @return
   */
  @Function("admin.dealerDepartment.user.update")
  @PostMapping(value = "/update")
  public ResponseMsg<String> update(
		  @RequestParam("userId") Long userId, 
		  @RequestParam("dealerDepartmentId") Long dealerDepartmentId,
		  @RequestParam("scope") Integer scope) {
	  userDealerDepartmentService.update(userId, dealerDepartmentId,scope);
	  return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS));
  }
  
  
  /**
   * 删除用户经销商层级
   * @param id 主键 
   * @return
   */
  @Function("admin.dealerDepartment.user.detele")
  @PostMapping(value = "/detele")
  public ResponseMsg<String> detele(@RequestParam("id") Long id) {
    userDealerDepartmentService.delete(id);
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS));
  }
  
  /**
   * 查询用户经销商层级
   * @param id 主键 
   * @return
   */
  @Function("admin.dealerDepartment.user.get")
  @GetMapping(value = "/get")
  public ResponseMsg<UserDealerDepartment> getById(@RequestParam("id") Long id) {
	  return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS),
			  userDealerDepartmentService.getById(id));
  }
  
  /**
   * 查询用户经销商层级列表
   * @param dealerDepartmentId 经销商层级主键
   * @return
   */
  @Function("admin.dealerDepartment.user.list")
  @GetMapping(value = "/list")
  public ResponseMsg<List<UserDealerDepartment>> list(@RequestParam("id") Long dealerDepartmentId) {
	  return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS),
			  userDealerDepartmentService.getByDealerDepartmentId(dealerDepartmentId));
  }
  

  
}
